package com.zhipu.balance.ui.vm;

import androidx.lifecycle.ViewModel;


import com.blankj.utilcode.util.GsonUtils;
import com.google.gson.Gson;
import com.zhipu.balance.remotedata.systemapi.SystemApiService;
import com.zhipu.balance.utils.CommonUtils;
import com.zhipu.balance.utils.InitializeUtils;

import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.disposables.Disposable;


public class BaseViewModel extends ViewModel {
    public boolean isRefresh;
    public int pageSize = 20;
    public int page = 1;

    public SystemApiService mSystemApiService;
    //管理RxJava，主要针对RxJava异步操作造成的内存泄漏
    private CompositeDisposable mCompositeDisposable;
    /**
     *
     */
    public Gson mGson = GsonUtils.getGson();




    public BaseViewModel(SystemApiService mSystemApiService) {
        this.mSystemApiService = mSystemApiService;
        mCompositeDisposable = new CompositeDisposable();

    }


    protected void addSubscribe(Disposable disposable) {
        if (mCompositeDisposable == null) {
            mCompositeDisposable = new CompositeDisposable();
        }
        mCompositeDisposable.add(disposable);
    }


    /**
     * 签名
     * @param mJson
     * @return
     */
    protected String toHexString(String mJson){
        byte[] byteSign = InitializeUtils.INSTANCE.getSignV0().signatureParams(mJson);
        return CommonUtils.INSTANCE.toHexString(byteSign);
    }

}
